package logic

import (
	"context"
	"gateway/internal/svc"
	"gateway/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type WebsocketClientListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewWebsocketClientListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WebsocketClientListLogic {
	return &WebsocketClientListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *WebsocketClientListLogic) WebsocketClientList() (*types.ListData, error) {
	// todo: add your logic here and delete this line
	var (
		resp = types.ListData{}
	)
	for _, item := range l.svcCtx.Manager.Clients {
		d := types.ClientData{}
		d.Id = item.ID
		d.AccountId = item.AccountId
		d.TaskId = item.Tasks.TaskId
		d.DeviceInfo = item.DeviceInfo
		resp.List = append(resp.List, d)
	}
	//err := comCopier.CopyWithOption(&resp.List, l.svcCtx.Manager.Clients)
	//if err != nil {
	//	return nil, err
	//}
	return &resp, nil
}
